home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 February (DVD) / PCWorld_2008-02_DVD.iso / v cisle / PHP / PHP.exe / EasyPHP-2.0b1-setup.exe / {app} / sqlitemanager / include / SQLiteTableProperties.class.php < prev    next >
Encoding:
PHP Script  |  2006-04-18  |  37.8 KB  |  903 lines

  1. <?php
  2. /**
  3. * Web based SQLite management
  4. * Show and manage 'TABLE' properties
  5. * @package SQLiteManager
  6. * @author FrΘdΘric HENNINOT
  7. * @version $Id: SQLiteTableProperties.class.php,v 1.115 2006/04/16 20:06:37 freddy78 Exp $ $Revision: 1.115 $
  8. */
  9.  
  10. include_once INCLUDE_LIB.'TableIndex.class.php';
  11.  
  12. class SQLiteTableProperties {
  13.  
  14.     /**
  15.     * reference to the connection object
  16.     *
  17.     * @access public
  18.     * @var object
  19.     */
  20.     var $connId;
  21.     
  22.     /**
  23.     * TABLE name
  24.     *
  25.     * @access private
  26.     * @var string
  27.     */
  28.     var $table;
  29.     
  30.     /**
  31.     * this TABLE exist?
  32.     *
  33.     * @access private
  34.     * @var bool
  35.     */
  36.     var $isExist;
  37.     
  38.     /**
  39.     * if this table have a PRIMARY KEY -> true
  40.     *
  41.     * @access private
  42.     * @var bool
  43.     */
  44.     var $tablePrimary;
  45.     
  46.     /**
  47.     * TABLE properties
  48.     *
  49.     * @access private
  50.     * @var array
  51.     */
  52.     var $infoTable;
  53.     
  54.     /**
  55.     * Class constructor
  56.     *
  57.     * @access public
  58.     * @param string $conn reference to the connection object
  59.     */
  60.     function SQLiteTableProperties(&$conn, $table=""){
  61.         // constructeur de la classe
  62.         $this->connId = $conn;
  63.         if(!empty($table)){
  64.             $this->table = $table;
  65.         } else if($GLOBALS['table']) {
  66.             $this->table = $GLOBALS['table'];
  67.         } elseif($GLOBALS['TableName']){
  68.             $this->table = $GLOBALS['TableName'];
  69.         } else return false;
  70.         if($GLOBALS["action"] != "delete") {        
  71.             $this->isExist = $this->tableExist($this->table);
  72.         } else {
  73.             $this->isExist = true;
  74.         }
  75.         return $this->isExist;
  76.     }
  77.     
  78.     
  79.     /**
  80.     * Get all the table properties
  81.     *
  82.     * @access public
  83.     * @param string $table table name
  84.     */
  85.     function getTableProperties($table=''){
  86.         if(empty($table)) $table = $this->table;
  87.         $this->connId->getResId('PRAGMA table_info('.brackets($table).');');
  88.         $this->infoTable = $this->connId->getArray();
  89.         $this->searchPrimaryKey($table);
  90.         return $this->infoTable;
  91.     }
  92.     
  93.     /**
  94.      * Get index SQL of table
  95.      * 
  96.      * @access private
  97.      */
  98.     function getIndexSQL() {
  99.         $query = "SELECT sql FROM sqlite_master WHERE tbl_name LIKE '".$this->table."';";
  100.         $this->connId->getResId($query);
  101.         $listIndex = $this->connId->getArray();
  102.         return $listIndex;
  103.     }
  104.  
  105.     /**
  106.     * Verify if this TABLE exist
  107.     *
  108.     * @access public
  109.     * @param string $table Table name
  110.     */
  111.     function tableExist($table){
  112.         if(empty($table)) $table = $this->table;
  113.         $this->connId->getResId("SELECT count(*) FROM sqlite_master WHERE type='table' AND name=".quotes($table).";");
  114.         if($this->connId->connId->fetch_single()>0) return true;
  115.         else return false;            
  116.     }
  117.     
  118.     /**
  119.     * search of all the index
  120.     *
  121.     * @access public
  122.     * @param string $table Table name
  123.     */
  124.     function searchPrimaryKey($table){
  125.         if(empty($table)) $table = $this->table;
  126.         $this->tablePrimary = false;
  127.         $this->connId->getResId("SELECT sql FROM sqlite_master WHERE type='table' and name=".quotes($table).";");
  128.         $sql = $this->connId->connId->fetch_single();
  129.         $firstPar     = strpos($sql, '(');
  130.         $endPar     = strrpos($sql, ')')-1;
  131.         $sql = substr($sql, ($firstPar+1), ($endPar - $firstPar));
  132.         $sql = str_replace("\n", '', $sql);
  133.         $ligne = explode(',', $sql);
  134.         while(list($ligneNum, $cont) = each($ligne)){
  135.             if(eregi('PRIMARY[[:space:]]KEY', $cont)){
  136.                 $tempCont = eregi_replace('PRIMARY[[:space:]]KEY', '', $cont);
  137.                 $tempCont = eregi_replace('\(|\)', '', $tempCont);
  138.                 $tabColName = explode(',', $tempCont);
  139.                 if(is_array($tabColName)) {
  140.                     foreach($tabColName as $colName) {
  141.                         $primaryKey = $this->numCol(trim($colName));
  142.                         $this->infoTable[$primaryKey]['primary'] = true;
  143.                         $this->tablePrimary = true;
  144.                     }
  145.                     return $primaryKey;
  146.                 } else {
  147.                     return false;
  148.                 }
  149.             }
  150.         }
  151.     }
  152.     
  153.     /**
  154.     * save current TABLE properties, add or modify
  155.     *
  156.     * @access public
  157.     */
  158.     function saveProp(){
  159.         $query = 'CREATE TABLE '.brackets($this->table).' ('."\n";
  160.         if(!$this->isExist) {
  161.             $error = false;
  162.             while(list($key, $value) = each($_POST['fieldName'])){
  163.                 if(!empty($_POST['fieldName'][$key])){
  164.                     $query .= brackets(cleanFieldName($value)).' '.$_POST['fieldType'][$key].(($_POST['fieldLength'][$key])? '('.stripslashes($_POST['fieldLength'][$key]).') ' : ' ' );
  165.                     $query .= $_POST['fieldNull'][$key];
  166.                     if(isset($_POST['primary']) && ($_POST['primary']==$key)) 
  167.                         $query .= ' PRIMARY KEY';
  168.                     $query .= (($_POST['fieldDefault'][$key] && ($_POST['fieldNull'][$key]=='NOT NULL'))? ' DEFAULT '.quotes($_POST['fieldDefault'][$key]) : '' ).",\n";
  169.                 }
  170.             }
  171.             $query = substr($query, 0, strlen($query)-2)."\n);";
  172.             $res = $this->connId->getResId($query);        
  173.             if($res) {
  174.                 $this->isExist = true;
  175.                 $this->getTableProperties();
  176.                 displayQuery($query);
  177.                 $this->tablePropView();
  178.                 echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=".$GLOBALS['dbsel']."';</script>";
  179.             }                
  180.             return;            
  181.         } else {
  182.             $listIndexSQL = $this->getIndexSQL();
  183.             $oldColumn = array();
  184.             $newColumn = array();
  185.             $nullToNotNull    = array();
  186.             if(isset($_POST['after']) && ($_POST['after']=='START')){
  187.                 while(list($key, $trash) = each($_POST['fieldName'])) if(!empty($_POST['fieldName'][$key])) $query .= $this->getPostProp($key);
  188.             }
  189.             if(is_array($this->infoTable)) {
  190.                 reset($this->infoTable);
  191.                 while(list($cid, $champ)=each($this->infoTable)){                
  192.                     if(isset($_POST['fieldName'][$cid]) && !isset($_POST['after'])) {
  193.                         $query .= $this->getPostProp($cid);    
  194.                         $oldColumn[] = $this->infoTable[$cid]['name'];
  195.                         $newColumn[] =     cleanFieldName($_POST['fieldName'][$cid]);
  196.                     } else{
  197.                         if(($GLOBALS['action'] == 'delete') && (isset($_POST['modify'][$cid]) && $_POST['modify'][$cid])) continue;
  198.                         $oldColumn[] = $this->infoTable[$cid]['name'];
  199.                         $query .= brackets($this->infoTable[$cid]['name']).' '.strtoupper($this->infoTable[$cid]['type']);
  200.                         $query .= (($this->infoTable[$cid]['notnull'])? ' NOT NULL' : '' );
  201.                         $noprimary         = ( (isset($GLOBALS['action']) && ($GLOBALS['action'] == 'noprimary'))  && isset($_POST['modify'][$cid]) && $_POST['modify'][$cid] );
  202.                         $addprimary     = ( (isset($GLOBALS['action']) && ($GLOBALS['action'] == 'addprimary')) && isset($_POST['modify'][$cid]) && $_POST['modify'][$cid] );
  203.                         if(!$noprimary && ( $addprimary || (isset($this->infoTable[$cid]['primary']) && $this->infoTable[$cid]['primary']) ) ) $query .= ' PRIMARY KEY';
  204.                         $query .= (($this->infoTable[$cid]['dflt_value'] && $this->infoTable[$cid]['notnull'])? ' DEFAULT '.quotes($this->infoTable[$cid]['dflt_value']) : '' ).",\n";
  205.                         $newColumn[] = $this->infoTable[$cid]['name'];
  206.                         if(isset($_POST['after']) && ($_POST['after']==(string)$cid)) {
  207.                             while(list($key, $trash) = each($_POST['fieldName'])){
  208.                                 if(!empty($_POST['fieldName'][$key])) $query .= $this->getPostProp($key);
  209.                             }
  210.                         }
  211.                     }
  212.                     if(isset($_POST['fieldNull'][$cid]) && !$this->infoTable[$cid]['notnull'] && ($_POST['fieldNull'][$cid]=='NOT NULL')) {
  213.                         $nullToNotNull[] = $this->infoTable[$cid]['name'];
  214.                     }                
  215.                 }
  216.             }
  217.             if(isset($_POST['after']) && ($_POST['after']=='END')){
  218.                 while(list($key, $trash) = each($_POST['fieldName'])) if(!empty($_POST['fieldName'][$key])) $query .= $this->getPostProp($key);
  219.             }
  220.             $query = substr($query, 0, strlen($query)-2)."\n);";
  221.         }
  222.         $condDrop = ( ($GLOBALS['action']=='delete') && !isset($_POST['modify']) );
  223.         $displayError = false;
  224.         if( !$condDrop && count($newColumn)>0) {
  225.             $GLOBALS['phpSQLiteError'] = '';
  226.             set_error_handler('phpSQLiteErrorHandling');            
  227.             $displayError = $this->connId->alterTable($this->table, $query, $oldColumn, $newColumn, $nullToNotNull);
  228.             restore_error_handler();
  229.             if(!$displayError) {
  230.                 // rebuild index
  231.                 if(is_array($listIndexSQL)) {
  232.                     foreach($listIndexSQL as $numIndex=>$indexSQL) {
  233.                         $res = @$this->connId->getResId($indexSQL['sql']);
  234.                     }        
  235.                 }
  236.             }
  237.         } else {
  238.             $this->connId->connId->query("BEGIN;", true, false);
  239.             $query = 'DROP TABLE '.brackets($this->table).';';
  240.             $res = $this->connId->connId->query($query, true, false);
  241.             $this->connId->connId->query("COMMIT;", true, false);
  242.         }
  243.  
  244.         $this->getTableProperties();
  245.         if($displayError) displayError($this->connId->errorMessage);
  246.         displayQuery($query);
  247.         if($GLOBALS['action'] != 'delete')  {
  248.             $this->tablePropView();
  249.             echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=".$GLOBALS['dbsel']."';</script>";
  250.         } else {
  251.             echo "<script type=\"text/javascript\">parent.left.location='left.php?dbsel=".$GLOBALS['dbsel']."'; parent.main.location='main.php?dbsel=".$GLOBALS['dbsel']."';</script>";
  252.         }
  253.     }
  254.  
  255.     /**
  256.     * create column propertie from Form
  257.     *
  258.     * @access private
  259.     * @param integer $index Number of column
  260.     */
  261.     function getPostProp($index){
  262.         $prop = brackets(cleanFieldName($_POST['fieldName'][$index])).' '.$_POST['fieldType'][$index].(($_POST['fieldLength'][$index])? '('.$_POST['fieldLength'][$index].') ' : ' ' );
  263.         $prop .= $_POST['fieldNull'][$index].((isset($_POST['primary'][$index]) && $_POST['primary'][$index])? ' PRIMARY KEY' : '' );
  264.         if($_POST['fieldDefault'][$index]!='') $prop .= ' DEFAULT '.quotes($_POST['fieldDefault'][$index]);
  265.         elseif($_POST['fieldNull'][$index]=='NOT NULL') $prop .= ' DEFAULT "'.$GLOBALS["SQLiteType"][$_POST['fieldType'][$index]].'"';        
  266.         $prop .= ",\n";
  267.         return $prop;
  268.     }
  269.     
  270.     /**
  271.     * Display TABLE form
  272.     *
  273.     * @access private
  274.     */
  275.     function tableEditForm(){
  276.         if(isset($_POST['modify']) && is_array($_POST['modify'])){
  277.             $nbChamp = count($_POST['modify']);
  278.             $tabIndex = array_keys($_POST['modify']);
  279.         } elseif($this->isExist && empty($GLOBALS['action'])) $nbChamp = count($this->infoTable);
  280.         else $nbChamp = $GLOBALS['nbChamps'];
  281.         if($nbChamp){ 
  282.           echo '<!-- SQLiteTableProperties.class.php : tableEditForm() -->'."\n";
  283.             echo '<br><center>';
  284.             if(!$this->isExist) echo '<h4>'.$GLOBALS['traduct']->get(25).' : ';
  285.             else echo '<h4>'.$GLOBALS['traduct']->get(26).' : ';
  286.             echo $this->table.'</h4>';
  287.             echo '<form name="tabprop" action="main.php?dbsel='.$GLOBALS['dbsel'].'" method="POST" target="main">';
  288.             echo '    <table class="Browse" cellpadding=0 cellspacing=0 width=80%>
  289.                         <thead>
  290.                         <tr>
  291.                             <td align="center" class="Browse">'.$GLOBALS['traduct']->get(27).'</td>
  292.                             <td align="center" class="Browse">'.$GLOBALS['traduct']->get(28).'</td>
  293.                             <td align="center" class="Browse">'.$GLOBALS['traduct']->get(29).'</td>
  294.                             <td align="center" class="Browse">'.$GLOBALS['traduct']->get(30).'</td>
  295.                             <td align="center" class="Browse">'.$GLOBALS['traduct']->get(31).'</td>
  296.                             <td align="center" class="Browse">'.$GLOBALS['traduct']->get(32).'</td>
  297.                         </tr>
  298.                         </thead>'."\n";
  299.             for($i=0 ; $i<$nbChamp ; $i++){
  300.                 if(isset($tabIndex)) $index = $tabIndex[$i];
  301.                 else $index = $i;
  302.                 $this->editFormLine($index);
  303.             }
  304.             echo '</table>';
  305.             echo '<input type="hidden" name="table" value="'.$this->table.'">'."\n".
  306.                  '<input type="hidden" name="action" value="save">'."\n";
  307.             if($GLOBALS['action'] == 'addChamp') echo '<input type="hidden" name="after" value="'.$_POST["after"].'">'."\n";
  308.             echo '<input class="button" type="submit" value="'.$GLOBALS['traduct']->get(51).'">';
  309.             echo '</form>';
  310.             echo '</center>';
  311.         } else $this->tablePropView();
  312.     }
  313.     
  314.     /**
  315.     * Display one column form
  316.     *
  317.     * @access private
  318.     * @param integer $index Number of column
  319.     */
  320.     function editFormLine($index){
  321.         if($GLOBALS['action'] != 'addChamp'){
  322.             if(isset($this->infoTable[$index]['name']))             $fieldName         = $this->infoTable[$index]['name']; else $fieldName = '';
  323.             if(isset($this->infoTable[$index]['notnull']))         $notnull         = $this->infoTable[$index]['notnull']; else $notnull = '';
  324.             if(isset($this->infoTable[$index]['dflt_value']))     $fieldDefault     = $this->infoTable[$index]['dflt_value']; else $fieldDefault = '';
  325.             if(isset($this->infoTable[$index]['primary']))         $fieldPrimary     = $this->infoTable[$index]['primary']; else $fieldPrimary = '';
  326.             if($pos=strpos($this->infoTable[$index]['type'], '(')){
  327.                 preg_match('/\((.*)\)/', $this->infoTable[$index]['type'], $lenType);
  328.                 $lenght = $lenType[1];    
  329.                 $type = substr($this->infoTable[$index]['type'], 0, $pos);
  330.             } else {
  331.                 $lenght = '';
  332.                 $type = $this->infoTable[$index]['type'];
  333.             }
  334.         } else {
  335.             $fieldName = $notnull = $fieldDefault = $fieldPrimary = '';
  336.             $type = '';
  337.             $lenght = '';
  338.         }
  339.       
  340.         $out = '<tr>
  341.                 <td align="center" class="Browse"><input type="text" class="text" name="fieldName['.$index.']" value="'.$fieldName.'"></td>
  342.                 <td align="center" class="Browse">
  343.         <select name="fieldType['.$index.']">'."\n";
  344.         $tabType = array_keys($GLOBALS['SQLiteType']);
  345.         asort($tabType);
  346.         foreach($tabType as $dispType) $out .= '             <option value="'.$dispType.'"'.((strtoupper($type)==$dispType)? ' selected="selected"' : '' ).'>'.$dispType.'</option>'."\n";
  347.         $out .= '     </select>'."\n".'</td>
  348.                 <td align="center" class="Browse"><input type="text" class="text" size="8" name="fieldLength['.$index.']" value="'.$lenght.'"></td>
  349.                 <td align="center" class="Browse"><select name="fieldNull['.$index.']">
  350.                         <option value="NOT NULL"'.(($notnull)? ' selected="selected"' : '' ).'>not null</option>
  351.                         <option value=""'.((!$notnull)? ' selected="selected"' : '' ).'>null</option>
  352.                     </select></td>
  353.                 <td align="center" class="Browse"><input type="text" class="text" name="fieldDefault['.$index.']" value="'.$fieldDefault.'"></td>
  354.                 <td align="center" class="Browse"><input type="radio" value="$index" name="primary" '.(($fieldPrimary)? ' checked="checked"' : '' ).'></td>
  355.                 </tr>';
  356.         echo $out;
  357.     }
  358.         
  359.     /**
  360.     * Display TABLE properties
  361.     *
  362.     * @access public
  363.     */
  364.     function tablePropView(){
  365.       echo '<!-- SQLiteTableProperties.class.php : tablePropView() -->'."\n";
  366.         if( (($GLOBALS['index_action'] == 'save') && empty($_POST['addCols'])) || ($GLOBALS['index_action'] == 'delete') ) {
  367.             $gestIndex =& new TableIndex($this->table, $this->infoTable);
  368.             displayQuery('');
  369.             unset($GLOBALS['indexSeq'], $_GET['indexSeq'], $_POST['indexSeq']);
  370.             unset($GLOBALS['index_action'], $_GET['index_action'], $_POST['index_action']);
  371.             unset($gestIndex);            
  372.         }
  373.         $out = '<br\>
  374.                 <div align="center">
  375.                 <table class="Main" cellpadding="0" cellspacing="0" width="80%">
  376.                     <tr>
  377.                         <td>
  378.                 <form name="tabprop" action="main.php?dbsel='.$GLOBALS['dbsel'].'" method="POST" target="main">
  379.                 <table class="Browse" cellpadding="0" cellspacing="0" width="100%">
  380.                     <thead>
  381.                     <tr>';
  382.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition('properties')) $out .= '            <td class="Browse"> </td>';
  383.         $out .= '            <td align="center" class="Browse">'.$GLOBALS['traduct']->get(27).'</td>
  384.                         <td align="center" class="Browse">'.$GLOBALS['traduct']->get(28).'</td>
  385.                         <td align="center" class="Browse">'.$GLOBALS['traduct']->get(30).'</td>
  386.                         <td align="center" class="Browse">'.$GLOBALS['traduct']->get(31).'</td>
  387.                         <td align="center" class="Browse" colspan="5">'.$GLOBALS['traduct']->get(33).'</td>
  388.                     </tr>
  389.                     </thead>';
  390.         if(is_array($this->infoTable)){
  391.             foreach($this->infoTable as $tableElement){
  392.                 if(isset($tableElement['cid'])) $out .= $this->linePropView($tableElement['cid']);
  393.             }
  394.         }
  395.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition('properties')) $out .= '    <tr><td colspan="10" class="BrowseSelect">   '.displayPics("arrow_ltr.gif")." 
  396.                 <a href=\"#\" onClick=\"javascript:setCheckBox('tabprop','modify',true);\" class=\"Browse\">".$GLOBALS["traduct"]->get(34)."</a> / 
  397.                 <a href=\"#\" onClick=\"javascript:setCheckBox('tabprop', 'modify', false);\" class=\"Browse\">".$GLOBALS["traduct"]->get(35)."</a> - <i>".$GLOBALS["traduct"]->get(36)."</i> : 
  398.                 <a href=\"#\" onClick=\"javascript: document.tabprop.action.value='modify'; document.tabprop.submit();\" class=\"Browse\">".displayPics("edit.png", $GLOBALS["traduct"]->get(14))."</a> - 
  399.                 <a href=\"#\" onClick=\"javascript: if(confirm('".$GLOBALS["traduct"]->get(37)."')) { document.tabprop.action.value='delete'; document.tabprop.submit();}\" class=\"Browse\">".displayPics("deletecol.png", $GLOBALS["traduct"]->get(15))."</a></td></tr>";
  400.         $out .= '</table>';
  401.         $out .= '<input type="hidden" name="table" value="'.$GLOBALS['table'].'">'."\n";
  402.         $out .= '<input type="hidden" name="action" value="">'."\n";
  403.         $out .= '</form>';
  404.         echo $out;
  405.         echo '<hr width="80%">';
  406.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition('properties')) $this->formAddChamp();
  407.         echo '<div class="TableOptions">'."\n";
  408.         echo '<div class="Indexes">'."\n";
  409.         echo '<h5>'.$GLOBALS['traduct']->get(38).'</h5>';
  410.         $gestIndex =& new TableIndex($this->table, $this->infoTable);
  411.         echo '</div>'."\n";
  412.         echo '</div>'."\n";
  413.         echo '</td>
  414.                 </tr>
  415.                 </table>
  416.                 </div>';
  417.         
  418.     }
  419.         
  420.     /**
  421.     * Display one column properties
  422.     *
  423.     * @access private
  424.     * @param integer $index Number of column
  425.     */
  426.     function linePropView($index){
  427.         if($index % 2) $localBgColor = $GLOBALS['browseColor1'];
  428.         else $localBgColor = $GLOBALS['browseColor2'];
  429.         $textConfirm = $GLOBALS['traduct']->get(39).'\n'.$this->infoTable[$index]['name'].'?';
  430.         if(!$this->infoTable[$index]['notnull']) $defltValue = '<i>NULL</i>';
  431.         elseif($this->infoTable[$index]['dflt_value']=='') $defltValue = ' ';
  432.         else $defltValue = $this->infoTable[$index]['dflt_value'];
  433.         $out = '';
  434.         $out .= "\t<tr bgcolor='".$localBgColor."' onMouseOver=\"setRowColor(this, $index, 'over', '".$localBgColor."', '".$GLOBALS['browseColorOver']."', '".$GLOBALS['browseColorClick']."')\"
  435.                                     onMouseOut=\"setRowColor(this, $index, 'out', '".$localBgColor."', '".$GLOBALS['browseColorOver']."', '".$GLOBALS['browseColorClick']."')\">\n";
  436.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition("properties")) $out .= '<td align="center" class="Browse"><input type="checkbox" name="modify['.$index.']"></td>'."\n";
  437.         $out .= '<td align="left" class="Browse">'.$this->infoTable[$index]['name'].'</td>'."\n";
  438.         $out .= '<td align="left" class="Browse">'.strtoupper($this->infoTable[$index]['type']).'</td>'."\n";
  439.         $out .= '<td align="center" class="Browse">'.((!$this->infoTable[$index]['notnull'])? $GLOBALS['traduct']->get(40) : $GLOBALS['traduct']->get(41) ).'</td>'."\n";
  440.         $out .= '<td align="right" class="Browse">'.$defltValue.'</td>'."\n";
  441.         
  442.         $out .= '<td align="center" class="Browse" width="7%">';
  443.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition("properties")) $out .= "<a href=\"#\" onClick=\"javascript:setTableAction('tabprop', ".$index.", 'modify');\" class=\"Browse\">".displayPics("edit.png", $GLOBALS['traduct']->get(14))."</a>";
  444.         else $out .= "<i>".displayPics("edit_off.png", $GLOBALS['traduct']->get(14))."</i>";
  445.         $out .= '</td>'."\n";
  446.         
  447.         $out .= '<td align="center" class="Browse" width="7%">';
  448.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition("properties")) $out .= "<a href=\"#\" onClick=\"javascript:if(confirm('".$textConfirm."')) setTableAction('tabprop', ".$index.", 'delete');\" class=\"Browse\">".displayPics("deletecol.png", $GLOBALS['traduct']->get(15))."</a>";
  449.         else $out .= "<i>".displayPics("deletecol_off.png", $GLOBALS['traduct']->get(15))."</i>";
  450.         $out .= '</td>'."\n";
  451.         
  452.         $out .= '<td align="center" class="Browse" width="7%">';
  453.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition("properties")) $out .= "<a href=\"#\" onClick=\"javascript:setTableAction('tabprop', ".$index.", 'unique');\" class=\"Browse\">".displayPics("unique.png", $GLOBALS['traduct']->get(197))."</a>";
  454.         else $out .= "<i>".displayPics("unique_off.png", $GLOBALS['traduct']->get(197))."</i>";
  455.         $out .= '</td>'."\n";
  456.  
  457.         $out .= '<td align="center" class="Browse" width="7%">';
  458.         if(!$GLOBALS['workDb']->isReadOnly() && displayCondition("properties")) $out .= "<a href=\"#\" onClick=\"javascript:setTableAction('tabprop', ".$index.", 'index');\" class=\"Browse\">".displayPics("index.png", $GLOBALS['traduct']->get(198))."</a>";
  459.         else $out .= "<i>".displayPics("index_off.png", $GLOBALS['traduct']->get(198))."</i>";
  460.         $out .= '</td>'."\n";
  461.  
  462.         $out .= '<td align="center" class="Browse" width="7%">';
  463.         if(($this->tablePrimary) && isset($this->infoTable[$index]['primary']) && ($this->infoTable[$index]['primary'])) {
  464.             if(!$GLOBALS['workDb']->isReadOnly() && displayCondition("properties")) $out .= "<a href=\"#\" onClick=\"javascript:setTableAction('tabprop', ".$index.", 'noprimary');\" class=\"Browse\">".displayPics("primaire.png", $GLOBALS['traduct']->get(42))."</a>";
  465.             else $out .= "<i>".displayPics("primaire_off.png", $GLOBALS['traduct']->get(42))."</i>";
  466.         } elseif(($this->tablePrimary) && (!isset($this->infoTable[$index]['primary']) || !($this->infoTable[$index]['primary']))) {
  467.             $out .= ' ';
  468.         } elseif(!$this->tablePrimary) {
  469.             if(!$GLOBALS['workDb']->isReadOnly() && displayCondition("properties")) $out .= "<a href=\"#\" onClick=\"javascript:setTableAction('tabprop', ".$index.", 'addprimary');\" class=\"Browse\">".displayPics("primaire.png", $GLOBALS['traduct']->get(42))."</a>";
  470.             else $out .= '<i>'.displayPics("primaire.png", $GLOBALS['traduct']->get(42)).'</i>';
  471.         }
  472.         $out .= '</td>';
  473.         $out .= '    </tr>';
  474.         return $out;
  475.     }
  476.     
  477.     /**
  478.     * Retreive the column number with his name
  479.     *
  480.     * @access public
  481.     * @param string $name Column name
  482.     */
  483.     function numCol($name){
  484.         if(is_array($this->infoTable))
  485.             while(list($cid, $champ)=each($this->infoTable))
  486.                 if($champ["name"]==$name) 
  487.                     return $cid;
  488.         return false;
  489.     }
  490.     
  491.     /**
  492.     * Display add column Form
  493.     *
  494.     * @access public
  495.     */
  496.     function formAddChamp(){
  497.         echo '<!-- SQLiteTableProperties.class.php : formAddChamp() -->'."\n";
  498.         echo '<form name="addChamp" action="main.php?dbsel='.$GLOBALS['dbsel'].'&table='.$this->table.'" method="POST" target="main">'."\n";
  499.         echo '<span style="font-size: 12px;">'.$GLOBALS['traduct']->get(43).' 
  500.                 <input type="text" name="nbChamps" value="1" size=2 class="small-input"> '.
  501.                 $GLOBALS['traduct']->get(44).' '."\n";
  502.         echo '<select name="after" class="small-input">'."\n";
  503.         echo '<option value="END">'.$GLOBALS['traduct']->get(45).'</option>'."\n";
  504.         echo '<option value="START">'.$GLOBALS['traduct']->get(46).'</option>'."\n";
  505.         foreach($this->infoTable as $champ) echo '<option value="'.$champ['cid'].'">'.$GLOBALS['traduct']->get(47).' '.$champ['name'].'</option>'."\n";
  506.         echo '</select>
  507.                 <input type="submit" value="'.$GLOBALS['traduct']->get(69).'" class="button small-input">'."\n";
  508.         echo '<input type="hidden" name="action" value="addChamp">'."\n";
  509.         echo '</span>
  510.                 </form>'."\n";
  511.     }
  512.  
  513.     /**
  514.     * Display Form for add or modify table record
  515.     *
  516.     * @access public
  517.     * @param string $req query where the record is
  518.     * @param integer $numId Number of the query record
  519.     * @param boolean $error if true, display POST value
  520.     */
  521.     function formElement($req='', $numId='', $error=false){
  522.         if(empty($req) && empty($numId)) $title = $GLOBALS['traduct']->get(48);
  523.         else $title = $GLOBALS['traduct']->get(49);
  524.         if(!empty($req)) $tabData = $this->recupElement($req, $numId, $error);
  525.         else $tabData = array();    
  526.     echo '<!-- SQLiteTableProperties.class.php : formElement() -->'."\n";        
  527.         echo '<center><h4>'.$title.'</h4>'."\n";
  528.         echo '<form name="editElement" action="main.php?dbsel='.$GLOBALS['dbsel'].'&table='.$this->table.'" method="POST" target="main">'."\n";
  529.         echo '    <table class="Insert" cellpadding="2" cellspacing="0" width="80%">
  530.                     <thead>
  531.                     <tr>
  532.                         <td align="center" class="Browse">'.$GLOBALS['traduct']->get(27).'</td>
  533.                         <td align="center" class="Browse">'.$GLOBALS['traduct']->get(28).'</td>
  534.                         <td align="center" class="Browse">'.$GLOBALS['traduct']->get(10).'</td>
  535.                         <td align="center" class="Browse">'.$GLOBALS['traduct']->get(30).'</td>
  536.                         <td align="center" class="Browse">'.$GLOBALS['traduct']->get(50).'</td>
  537.                     </tr>
  538.                     </thead>';
  539.         reset($this->infoTable);
  540.         while(list($cid, $tabInfo) = each($this->infoTable)){
  541.             $this->lineElement($tabInfo, $tabData);    
  542.         }        
  543.         echo '</table>';
  544.         echo '<input type="hidden" name="action" value="saveElement">'."\n";
  545.         if(isset($_REQUEST['currentPage'])) echo '<input type="hidden" name="currentPage" value="'.$_REQUEST['currentPage'].'">'."\n";
  546.         if($req) {
  547.             echo '<input type="hidden" name="numId" value="'.$numId.'">'."\n";
  548.             echo '<input type="hidden" name="req" value="'.urlencode($req).'">'."\n";
  549.         }
  550.         echo '<table width=80% align="center"><tr><td>';
  551.         $fontSize = "10px";
  552.         if($GLOBALS["action"]!= "insertElement") {
  553.             echo '<!--save type--><table><tr><td style="white-space: nowrap; font-size: '.$fontSize.';">'.$GLOBALS['traduct']->get(221).' : </td>
  554.                     <td><input type="radio" name="save_type" value="as_new_row"></td>
  555.                     <td style="font-size: '.$fontSize.';">: '.$GLOBALS['traduct']->get(219).'</td></tr>
  556.                     <tr><td> </td>
  557.                     <td><input type="radio" name="save_type" value="save" checked="checked"></td>
  558.                     <td style="font-size: '.$fontSize.';">: '.$GLOBALS['traduct']->get(220).'</td></tr></table><br/><!--end save type-->'."\n";
  559.         } else {
  560.             echo '<div align="center" style="font-size: '.$fontSize.';">'.$GLOBALS['traduct']->get(219).'</div>';
  561.         }
  562.         echo '</td><td align="right">';
  563.  
  564.         echo '<table><tr><td style="white-space: nowrap; font-size: '.$fontSize.';">'.$GLOBALS['traduct']->get(151).' : </td>
  565.                 <td><input type="radio" name="after_save" value="'.((isset($_REQUEST['currentPage']) && !empty($_REQUEST['currentPage']))? $_REQUEST['currentPage'] : ((isset($_REQUEST['after_save']) && !empty($_REQUEST['after_save']))? $_REQUEST['after_save'] : 'properties' ) ).'"'.((!isset($_POST['after_save']) || !empty($_POST['after_save']))? ' checked="checked"' : '' ).'></td>
  566.                 <td style="font-size: '.$fontSize.';">: '.$GLOBALS['traduct']->get(152).'</td></tr>
  567.                 <tr><td> </td>
  568.                 <td><input type="radio" name="after_save" value=""'.((isset($_REQUEST['after_save']) && ($_REQUEST['after_save']==''))? ' checked="checked"' : '' ).'></td>
  569.                 <td style="font-size: '.$fontSize.';">: '.$GLOBALS['traduct']->get(153).'</td></tr></table><br/>'."\n";
  570.  
  571.         echo '</td></tr></table>';
  572.         
  573.         echo '<input class="button" type="submit" value="'.$GLOBALS['traduct']->get(51).'" onclick="document.tabprop.submit();">';
  574.         echo '</form>';
  575.         echo '</center>'."\n";
  576.         echo '<br/>'.str_repeat(' ', 10).'» <a href="main.php?dbsel='.$GLOBALS['dbsel'].'&table='.$this->table.'&action=insertFromFile" class="base" target="main">'.$GLOBALS['traduct']->get(52).'</a>';
  577.         return;
  578.     }
  579.     
  580.     /**
  581.     * Display on column for inert modify record
  582.     *
  583.     * @access private
  584.     * @param array $infoTable table properties
  585.     * @param array $tabValue current value for modify record
  586.     */
  587.     function lineElement($infoTable, $tabValue=''){
  588.         $simpleType = strtoupper(substr($infoTable['type'],0,4));
  589.         if(($simpleType == 'TEXT') || ($simpleType == 'BLOB')) $BigInput = true; else $BigInput = false;
  590.         if($BigInput && ADVANCED_EDITOR && (!isset($_COOKIE["SQLiteManager_HTMLon"]) || !$_COOKIE["SQLiteManager_HTMLon"])) $CheckreadOnly = ' DISABLED'; else $CheckreadOnly = '';
  591.         if(!isset($tabValue[$infoTable['name']])) $tabValue[$infoTable['name']] = '';
  592.         echo '    <tr>
  593.                     <td align="left" class="Insert">'.$infoTable['name'].'</td>
  594.                     <td align="center" class="Insert">'.StrToUpper($infoTable['type']).'</td>
  595.                     <td align="center" class="Insert">'.SQLiteFunctionList($infoTable['name']).'</td>
  596.                     <td align="center" class="Insert">';            
  597.         if(!$infoTable['notnull'] || isset($infoTable['primary'])){
  598.             $CheckNull =  '<input type="checkbox" name="nullField['.$infoTable['name'].']" ';
  599.             if($tabValue[$infoTable['name']]=='') $CheckNull .= 'checked="checked"';
  600.             $CheckNull .= $CheckreadOnly;
  601.             $CheckNull .= ' onChange="if(this.checked) cleanNullField(\'editElement\', \''.$infoTable['name'].'\');">';
  602.         } else {
  603.              $CheckNull = ' ';
  604.         }
  605.         echo $CheckNull.'</td>
  606.                     <td align="left" class="Insert">';
  607.         echo SQLiteInputType($infoTable, $tabValue[$infoTable['name']]);
  608.         echo '</td>
  609.                 </tr>';
  610.         return;
  611.     }
  612.     
  613.     /**
  614.     * save record
  615.     *
  616.     * @access private
  617.     */
  618.     function saveElement(){
  619.         if(isset($_GET['pos'])) $GLOBALS['numId'] = $_GET['pos'];
  620.         if(isset($_REQUEST['numId'])) $GLOBALS['numId'] = $_REQUEST['numId'];
  621.         if(isset($_GET['query'])) $GLOBALS['req'] = urldecode($_GET['query']);
  622.         elseif(isset($_POST['req'])) $GLOBALS['req'] = urldecode($_POST['req']);
  623.         if(isset($GLOBALS['req']) && isset($GLOBALS['numId'])){
  624.             $oldValue = $this->recupElement($GLOBALS['req'], $GLOBALS['numId']);
  625.         }
  626.  
  627.         if(isset($_POST['valField']) && is_array($_POST['valField'])){
  628.             while(list($champ, $value) = each($_POST['valField'])){
  629.                 $value = stripslashes($value);
  630.                 $cid = $this->getCID($champ);
  631.                 $tempType = $this->infoTable[$cid]['type'];
  632.                 if(isset($_POST['funcs'][$champ]) && !empty($_POST['funcs'][$champ])){
  633.                     if(eregi('CHAR|TEXT|LOB|DATE', $tempType)) $funcVal = quotes($value);
  634.                     else $funcVal = $value;
  635.                     $value = applyFunction($_POST['funcs'][$champ], $funcVal);
  636.                 } elseif(!isset($_POST['nullField'][$champ]) || !$_POST['nullField'][$champ]) {
  637.                     if($tempType) {
  638.                         if(eregi('CHAR|TEXT|LOB|DATE', $tempType)) $value = quotes($value);
  639.                     } else
  640.                         $value = quotes($value);
  641.                 }
  642.  
  643.                 if(isset($_POST['nullField'][$champ])) {
  644.                     $value = 'NULL';
  645.                 }
  646.                 if(!isset($_POST['numId']) || $_POST['save_type']=="as_new_row"){
  647.                     $listColumn[]     = brackets($champ);
  648.                     $listValue[]    = $value;
  649.                 } else {
  650.                     if((isset($oldValue[$champ]) && ($value != quotes($oldValue[$champ])) || (!isset($oldValue[$champ])&& ($value != "NULL")))){
  651.                         $listColumn[]    = brackets($champ).'='.$value;
  652.                     }
  653.                 }
  654.                 
  655.             }
  656.         }
  657.  
  658.         $query = '';
  659.         if($GLOBALS['action']=='deleteElement'){
  660.             $query = 'DELETE FROM '.brackets($GLOBALS['table']).' WHERE ROWID='.$oldValue['ROWID'];
  661.         } elseif(isset($_POST['numId']) && $_POST['save_type']!="as_new_row"){
  662.             if(isset($listColumn) && !empty($listColumn)){                 
  663.                 $query = 'UPDATE '.brackets($GLOBALS['table']).' SET '.implode(', ', $listColumn).' WHERE ROWID='.$oldValue['ROWID'];
  664.             }
  665.         } else {
  666.             if(isset($listColumn) && isset($listValue)) 
  667.                 $query = 'INSERT INTO '.brackets($GLOBALS['table']).' ('.implode(', ', $listColumn).') VALUES ('.implode(', ', $listValue).')';
  668.         }        
  669.         displayQuery($query);
  670.         $errorCode = false;
  671.         if(isset($query) && !empty($query)){
  672.             $this->connId->getResId('BEGIN;');
  673.             if(!$this->connId->getResId($query)){
  674.                 echo '<center><span style="color: red;">'.$GLOBALS['traduct']->get(9).' : '.@$this->connId->connId->getError().'</span></center>';
  675.                 $this->formElement($GLOBALS['req'], $GLOBALS['numId'], true);
  676.             }
  677.             $this->connId->getResId('COMMIT;');
  678.         }
  679.         // return management        
  680.         if(!isset($_REQUEST['after_save']) && isset($_REQUEST['currentPage'])) $_REQUEST['after_save'] = $_REQUEST['currentPage'];
  681.         if(!$errorCode && isset($_REQUEST['after_save'])){
  682.             if($_REQUEST['after_save'] == '') $this->formElement(((isset($GLOBALS['req']))? $GLOBALS['req'] : '' ), ((isset($GLOBALS['numId']))? $GLOBALS['numId'] : '' ));
  683.             else 
  684.                 switch($_REQUEST['after_save']){
  685.                     case '':
  686.                     case 'properties':
  687.                         $this->tablePropView();
  688.                         break;
  689.                     case 'browseItem':
  690.                         if(isset($GLOBALS['numId'])){
  691.                             $GLOBALS['noDisplay'] = true;
  692.                             include_once INCLUDE_LIB.'ParsingQuery.class.php';
  693.                             $tabRes = ParsingQuery::noLimit($GLOBALS['req']);
  694.                             $GLOBALS['DisplayQuery'] = $tabRes['query'];
  695.                             $GLOBALS['pageBrowse'] = $_GET['pageBrowse'] = $tabRes['page'];
  696.                         }
  697.                         $GLOBALS['reBrowse'] = true;
  698.                         break;
  699.                 }
  700.         }
  701.     }
  702.     
  703.     /**
  704.     * Form for insert data from text file formatted
  705.     *
  706.     * @access public
  707.     */
  708.     function formFromFile(){
  709.     echo '<!-- SQLiteTableProperties.class.php : formFromFile() -->'."\n";        
  710.         echo '<div align="center">'."\n";
  711.         echo '<br/><h4>'.$GLOBALS['traduct']->get(140).'</h4><br/>';
  712.         echo '<form name="fromfile" action="main.php?dbsel='.$GLOBALS['dbsel'].'&table='.$GLOBALS['table'].'" method="POST" ENCTYPE="multipart/form-data" target="main">'."\n";
  713.         echo '<table border="1" width="70%">'."\n";
  714.         echo '<tr><td>'.$GLOBALS['traduct']->get(137).'</td><td> <input type="file" class="file" name="fileInsert"></td></tr>';
  715.         echo '<tr><td>'.$GLOBALS['traduct']->get(138).'</td><td><input type="checkbox" name="replaceAll"></td></tr>';
  716.         echo '<tr><td>'.$GLOBALS['traduct']->get(139).'</td><td> <input type="text" class="text" name="separator" value="\t" size=5></td></tr>';
  717.         echo '</table>'."\n";
  718.         echo '<input class="button" type="submit" value="'.$GLOBALS['traduct']->get(69).'">'."\n";
  719.         echo '<input type="hidden" name="action" value="saveFromFile">';
  720.         echo '</form>';
  721.         echo '</div>'."\n";
  722.     }
  723.     
  724.     /**
  725.     * Save data from text file formatted
  726.     *
  727.     * @access private
  728.     */
  729.     function saveFromFile(){
  730.         if($_POST['separator'] != '\\\t') $useDelim = ' USING DELIMITERS '.quotes($_POST['separator']);
  731.         else $useDelim = '';
  732.         $GLOBALS['DisplayQuery'] = $copyQuery = 'COPY '.brackets($this->table).' FROM '.quotes($_FILES['fileInsert']['tmp_name']).$useDelim.';';
  733.         if($this->connId->connId->getVersion()!=3){
  734.             $query[] = "BEGIN;";
  735.             if(!empty($_FILES['fileInsert']['tmp_name'])){
  736.                 if(isset($_POST['replaceAll']) && $_POST['replaceAll']){
  737.                     $query[] = 'DELETE FROM '.brackets($this->table).';';
  738.                 }
  739.                 $query[] = $copyQuery;
  740.                 $query[] = "COMMIT;";
  741.             }
  742.         } else {
  743.             // build save from file for SQLITE3
  744.             $fileToLine = file($_FILES['fileInsert']['tmp_name']);
  745.             if(is_array($fileToLine)){
  746.                 $query[] = "BEGIN;";
  747.                 if(isset($_POST['replaceAll']) && $_POST['replaceAll']){
  748.                     $query[] = 'DELETE FROM '.brackets($this->table).';';
  749.                 }
  750.                 if($_POST['separator'] == '\\\t') $sep = "\t";
  751.                 else $sep = $_POST['separator'];
  752.                 foreach($fileToLine as $record){
  753.                     $recordElement = explode($sep, rtrim($record));
  754.                     $query[] = "INSERT INTO ".brackets($this->table)." VALUES ('".implode("', '", $recordElement)."');";
  755.                 }
  756.                 $query[] = "COMMIT;";
  757.             }            
  758.         }
  759.         $execError = false;
  760.         $GLOBALS['phpSQLiteError'] = '';
  761.         set_error_handler('phpSQLiteErrorHandling');                    
  762.         foreach($query as $q){
  763.             if(!$this->connId->getResId($q)){            
  764.                 $execError = true;
  765.                 $this->connId->getResId("ROLLBACK TRANSACTION;");
  766.                 $errorMessage = '<table style="color: red;"><tr><td>'.$GLOBALS['traduct']->get(9).' :</td><td>'.$this->connId->connId->getError().'</td></tr>';
  767.                 if($GLOBALS['phpSQLiteError'] != '') $errorMessage .= '<tr><td> </td><td>'.$GLOBALS['phpSQLiteError'].'</td></tr>';
  768.                 $errorMessage .= '</table>';
  769.                 break;
  770.             }        
  771.         }
  772.         restore_error_handler();
  773.         if($execError) {
  774.             displayError($errorMessage);        
  775.             displayQuery($GLOBALS['DisplayQuery']);
  776.             $this->formFromFile();
  777.         } else {
  778.             displayQuery($GLOBALS['DisplayQuery']);
  779.         }
  780.     }
  781.     /**
  782.     * Retrive Record from current query and numId
  783.     *
  784.     * @access public
  785.     * @param string $req current query
  786.     * @param integer $numId Number of record from current query
  787.     * @param boolean $error if true return POST value
  788.     */
  789.     function recupElement($req, $numId, $error=false){
  790.         include_once INCLUDE_LIB.'ParsingQuery.class.php';
  791.         $tabQueryElement = ParsingQuery::explodeSelect($req);
  792.  
  793.         $tabQueryElement['SELECT'] = 'ROWID, '.$tabQueryElement['SELECT'];
  794.  
  795.         if(eregi('FROM', $req)){
  796.             $tabFrom = explode(',', $tabQueryElement['FROM']);
  797.             foreach($tabFrom as $key=>$value) $tabFrom[$key] = brackets($value);
  798.             $tabQueryElement['FROM'] = implode(',', $tabFrom);
  799.         }
  800.  
  801.         if(eregi('LIMIT', $req)){
  802.             $tabLimit = explode(',', $tabQueryElement['LIMIT']);
  803.             $tabQueryElement['LIMIT'] = ((int)$tabLimit[0]+$numId).',1';
  804.         } else {
  805.             $tabQueryElement['LIMIT'] = $numId.',1';
  806.         }
  807.         
  808.         $querySearch = '';
  809.         foreach($tabQueryElement as $clause=>$contentClause) $querySearch .= $clause.' '.$contentClause.' ';
  810.  
  811.         $this->connId->connId->query($querySearch);
  812.         $tabData = $this->connId->connId->fetch_array(null, (($this->connId->connId->getVersion()==3)? SQLITE_BOTH : SQLITE_ASSOC ));
  813.         if($this->connId->connId->getVersion()==3) $tabData["ROWID"] = $tabData[0];
  814.         if($error){
  815.             foreach($tabData as $fieldname => $fieldvalue) 
  816.                 if(isset($_POST[$fieldname])) $tabData[$fieldname] = $_POST[$fieldname];
  817.         }
  818.         return $tabData;
  819.     }
  820.     
  821.     /**
  822.     * Retrive 'cid' from champ name
  823.     *
  824.     * @access public
  825.     * @param string $name
  826.     */
  827.     function getCID($name){
  828.         foreach($this->infoTable as $cid => $info)
  829.             if($info['name']==$name) return $cid;
  830.     }
  831.     
  832.     /**
  833.     *
  834.     */
  835.     function saveKey(){
  836.         $cid = key($_POST['modify']);
  837.         $columnName = $this->infoTable[$cid]['name'];
  838.         if($_POST['action']=='unique') $type = 'UNIQUE ';
  839.         else $type = '';
  840.         $query = 'CREATE '.$type.'INDEX '.str_replace(' ','_',$this->table.'_'.$columnName).' ON '.brackets($this->table).'('.brackets($columnName).');';
  841.         $GLOBALS['phpSQLiteError'] = '';
  842.         set_error_handler('phpSQLiteErrorHandling');
  843.         if(!$this->connId->getResId($query)){            
  844.                 echo '<table align="center" style="color: red;"><tr><td>'.$GLOBALS['traduct']->get(9).' :</td><td>'.@$this->connId->connId->getError().'</td></tr>';
  845.                 if($GLOBALS['phpSQLiteError'] != '') echo '<tr><td> </td><td>'.$GLOBALS['phpSQLiteError'].'</td></tr>';
  846.                 echo '</table>';
  847.         }
  848.         restore_error_handler();
  849.         displayQuery($query);
  850.         $this->tablePropView();
  851.     }
  852.     
  853.     
  854.     /**
  855.     * Generate SQL query for 'select'
  856.     * @author Maurφcio M. Maia <mauricio.maia@gmail.com>
  857.     *
  858.     * @param string $table
  859.     */
  860.     function selectElement($table) {
  861.         $showField = $_REQUEST['showField'];
  862.         $valField = $_REQUEST['valField'];
  863.         $operats = $_REQUEST['operats'];
  864.         $error = false;
  865.         $selectQuery = 'SELECT ';
  866.         $condQuery = '';
  867.         if(is_array($_REQUEST['showField']) && !empty($_REQUEST['showField'])){
  868.             $selectQuery .= implode(", ", array_keys($_REQUEST['showField']));
  869.         } else $selectQuery .= '*';
  870.         
  871.         $fromQuery = ' FROM '.brackets($table).' ';
  872.         if(is_array($_REQUEST['valField']) && !empty($_REQUEST['valField'])){
  873.             foreach($valField as $key => $value) {
  874.                 if (    (isset($value) && !empty($value)) 
  875.                         || (isset($operats[$key])
  876.                         && !empty($operats[$key]))) {
  877.     
  878.                     if($operats[$key] == 'ISNULL' || $operats[$key] == 'NOTNULL'){
  879.                         $condQuery .= $key.' '.$operats[$key];
  880.                     } else if($operats[$key]=="fulltextsearch"){
  881.                         if($selectQuery == "SELECT *"){
  882.                             $condQuery .= 'fulltextsearch('.$key.', '.quotes($value).', 0) > 0';
  883.                         } else {
  884.                             $selectQuery .= ', fulltextsearch('.$key.', '.quotes($value).', 0) AS '.$key.'Match';
  885.                             $condQuery .= $key.'Match > 0'; 
  886.                         }
  887.                     } else {
  888.                         $condQuery .= $key.' '.$operats[$key].' '.quotes($value);
  889.                     }
  890.                 }
  891.             }
  892.         }
  893.         if(!empty($_REQUEST['CondSuppl'])){
  894.             if($condQuery) $condQuery .= ' '.$_REQUEST['operSuppl'].' ';
  895.             $condQuery .= $_REQUEST['CondSuppl'];
  896.         }
  897.         return $selectQuery.$fromQuery.(($condQuery)? 'WHERE '.$condQuery : '' );
  898.     }
  899.  
  900. }
  901.  
  902. ?>
  903.